<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include::header"></head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">       
        <div class="row">        
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>修改密码</h5>                      
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="myForm" th:action="@{${basePath}+'/doPwd'}" method="get">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">当前密码：</label>
                                <div class="col-sm-4">
                                    <input id="old_password" name="old_password" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">新密码：</label>
                                <div class="col-sm-4">
                                    <input id="password" name="password" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">确认密码：</label>
                                <div class="col-sm-4">
                                    <input id="confirm_password" name="confirm_password" class="form-control" type="password">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button id="btnSubmit" class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 提交</button>
                                    <button  class="btn btn-danger" type="button" onclick="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div th:include="include::footer"></div>
	<script th:inline="javascript">
        var basePath=[[${basePath}]];
        $().ready(function() {
            var e = "<i class='fa fa-times-circle'></i> ";
            $("#myForm").validate({
                rules: {
                    old_password: {
                        required: !0,
                        minlength: 6
                    },
                    password: {
                        required: !0,
                        minlength: 6
                    },
                    confirm_password: {
                        required: !0,
                        minlength: 6,
                        equalTo: "#password"
                    }
                },
                messages: {
                    old_password: {
                        required: e + "请输入当前的密码",
                        minlength: e + "密码必须6个字符以上"
                    },
                    password: {
                        required: e + "请输入您的密码",
                        minlength: e + "密码必须6个字符以上"
                    },
                    confirm_password: {
                        required: e + "请再次输入密码",
                        minlength: e + "密码必须6个字符以上",
                        equalTo: e + "两次输入的密码不一致"
                    }
                }
            });

            $('#myForm').on('submit', function() {
                $(this).ajaxSubmit({
                    type: 'post',
                    beforeSubmit:function(){
                        return $("#myForm").valid();
                    },
                    success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        if(data.status==200){
                            layer.msg(data.message,{icon: 6,time:2000,shade: 0.1},function(index){
                               parent.window.location.href =basePath+"/index";
                            });
                        }else{
                            layer.msg(data.message);
                        }
                    }
                });
                return false; // 阻止表单自动提交事件
            });

        });
	</script>
</body>

</html>

